#ifndef DEMOMANAGER_H
#define DEMOMANAGER_H


#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QDBusInterface>
#include <QObject>
#include <QTimer>

#include "clib-syslog.h"
#include "usd_base_class.h"
#include "QGSettings/qgsettings.h"

#include "gamma-manager-gtkconfig.h"
#include "gamma-manager-define.h"
#include "gamma-manager-dbus.h"
#include "gamma-manager-adaptor.h"
#include "gamma-manager-thread.h"
#include "gamma-manager-helper.h"
#include "gamma-manager-location.h"
#include "plugin-manager-interface.h"

class GammaManager : public ManagerInterface
{
    Q_OBJECT
public:
    GammaManager();
    GammaManager(GammaManager&)=delete;
    GammaManager&operator=(const GammaManager&)=delete;
public:
    ~GammaManager();
    static GammaManager *GammaManagerNew();

    virtual bool Start();
    virtual void Stop();
    void setLocationIp(QStringList addresses);//for test
    bool ReadKwinColorTempConfig();
    OutputGammaInfo getScreensInfo();
    OutputGammaInfoList getScreensInfoList();
    int setTemperature(const uint value);//设置色温、亮度目标值，其余算法由另外的help解决。
public Q_SLOTS:
    void doQtSettingsChanged(QString key);
    void doColorSettingsChanged(QString key);
    void doReckTimeout();
    void doSetScreenBrightness(QString screenName, int screenBrightness);
private:
    bool isDarkMode(QString key);
    bool isFracDayBetween (double  value, double start, double end);
    void gammaRecheck(QString key);

    void setBrightness(const uint value);


    double getFracTimeFromDt(QTime dt);
    double linearInterpolate(double val1, double val2, double factor);
private:
    QGSettings *m_pColorSettings;
    QGSettings *m_pQtSettings;
    QGSettings *m_pGtkSettings;

    QTimer      *m_pReckTimer;
    GmHelper    *m_pGmHelper;
    GmLocation  *m_pGmLocation;
    GmThread    *m_pGmThread;
    GmAdaptor   *m_pGmAdaptor;
    GmDbus      *m_pGmDbus;
    UkuiGtkConfig *m_pukuiGtkConfig;
    int  m_cachedTemperature;
    bool m_darkModeChangedBySelf;
    static GammaManager *m_gammaManager;
};


#endif // DEMOMANAGER_H
